var permute = function(nums) {

  const ans = [], path = [], used = new Array(21).fill(0);

  backtracking(nums, ans, path, used);

  return ans;

};

function  backtracking(nums, ans, path, used) {
  if (path.length === nums.length) {
    ans.push([...path]);
    return;
  }

  for (let i = 0; i < nums.length; i++) {
    // 已经访问了
    if (used[nums[i] + 10] === 1) {
      continue;
    }
    used[nums[i] + 10] = 1;
    path.push(nums[i]);
    backtracking(nums, ans, path, used);
    path.pop();
    used[nums[i] + 10] = 0;
  }
} 


const nums = [1,2,3]
console.log(permute(nums))